<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class ProductClass
 * 
 * @property int $id
 * @property string|null $category_name
 * @property int|null $pid
 * @property string|null $status
 * @property int|null $app_status
 * @property int|null $wx_xcx_status
 * @property int|null $pc_status
 * @property string|null $remark
 * @property Carbon|null $update_time
 * @property Carbon|null $create_time
 * @property float|null $max_money
 * @property float|null $after_money
 * @property float|null $surplus_money
 * 
 * @property Collection|Product[] $products
 * @property Collection|Branch[] $branches
 *
 * @package App\Models
 */
class ProductClass extends Model
{
	protected $table = 'product_class';

	protected $casts = [
		'pid' => 'int',
		'app_status' => 'int',
		'wx_xcx_status' => 'int',
		'pc_status' => 'int',
		'max_money' => 'float',
		'after_money' => 'float',
		'surplus_money' => 'float'
	];

	protected $fillable = [
		'category_name',
		'pid',
		'status',
		'app_status',
		'wx_xcx_status',
		'pc_status',
		'remark',
		'max_money',
		'after_money',
		'surplus_money'
	];

	public function products()
	{
		return $this->hasMany(Product::class, 'class_id');
	}

	public function branches()
	{
		return $this->belongsToMany(Branch::class, 'product_class_branch')
					->withPivot('id', 'is_display')
					->withTimestamps();
	}
}
